package com.xinqi.modules.homework.homework.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.R;
import com.xinqi.common.core.enums.StudentOperateGroup;
import com.xinqi.common.core.enums.StudentSwitchType;
import com.xinqi.modules.homework.homework.client.CourseHomeworkClient;
import com.xinqi.modules.homework.homework.dto.req.CourseHomeworkStudentDetailDTO;
import com.xinqi.modules.homework.homework.dto.req.CourseHomeworkUpdateDTO;
import com.xinqi.modules.homework.homework.dto.rsp.CourseHomeworkResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 班级降级处理
 *
 * @author: system
 * @date: 2023/01/12
 */
@Slf4j
@Component
public class CourseHomeworkFallbackFactory implements FallbackFactory<CourseHomeworkClient> {

    @Override
    public CourseHomeworkClient create(Throwable throwable) {
        log.error("作业服务调用失败:{}", throwable.getMessage());
        return new CourseHomeworkClient() {

            @Override
            public R<String> timingRun() {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<String> timesInProgressRun() {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<String> timesClosedRun() {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<String> studentOperateGroup(Long classId, Long studentId, Long groupId, StudentOperateGroup operateGroup) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Void> studentJoinClass(Long classId, Long studentId) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Void> studentIdentitySwitch(Long classId, Long studentId, StudentSwitchType switchType) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<CourseHomeworkResultDTO> findById(Long id, CourseHomeworkStudentDetailDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<String> update(Long id, CourseHomeworkUpdateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}
